package com.woldier.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woldier.common.R;
import com.woldier.dto.OrdersDto;
import com.woldier.entity.Orders;
import com.woldier.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;


    @PostMapping("submit")
    public R submit(@RequestBody Orders orders){

        /*插入order 并且设置order_detail*/
        orderService.saveWithDetail(orders);
        return R.success("订单提交成功");
    }

    @GetMapping("userPage")
    public R getUserPage(int page , int pageSize){

        Page<OrdersDto> orderWithDetails = orderService.getOrderWithDetails(page, pageSize);

        return R.success(orderWithDetails);
    }
    @GetMapping("page")
    public R getPage(int page , int pageSize){

        Page<OrdersDto> orderWithDetails = orderService.getOrderWithDetails(page, pageSize);

        return R.success(orderWithDetails);
    }

}
